package task

import (
	"fmt"
	"gitee.com/dn-jinmin/chatcms/internal/svc"
	"github.com/jasonlvhit/gocron"
)

type Service interface {
	Run()
	Fix()
}

type Serve struct {
	svc *svc.ServiceContext
}

func NewServe(svc *svc.ServiceContext) *Serve {
	return &Serve{
		svc: svc,
	}
}
func (s *Serve) Services() []Service {
	return []Service{
		// to task
		NewSpeechcraft(s.svc),
	}
}

func (s *Serve) Start() {
	for _, service := range s.Services() {
		service.Fix()
	}

	for _, service := range s.Services() {
		service.Run()
	}

	fmt.Println("启动定时任务...")

	<-gocron.Start()
}
